import { useReactive } from "ahooks";
import { useModel } from "umi";
import { useEffect } from "react";
import compress from "gql-compress";

const useAllMembers = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        loading: false,
        members: [],
    });

    const loadAllMembers = async () => {
        state.loading = true;
        let res = await graphqlFetch({
            query,
            variables: {
                omAust: "已认证",
            },
        });
        state.members = res?.a?.nodes || [];
        state.loading = false;
    };

    useEffect(() => {
        loadAllMembers();
    }, []);

    return { ...state, loadAllMembers };
};

const query = compress(`query MyQuery($omAust: String!) {
    a:allOrganizationMembers(condition: {omAust: $omAust}, orderBy: OM_PINY_ASC) {
        nodes {
            omName
            omPosi
            omIfim
            omRnve
            omRoge
            omUuid
            omEona
            omEouu
            omAvta
            omAust
        }
    }
}`);

export default useAllMembers;
